package com.yunchen.BooksManagementSystem.Filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;

@WebFilter(filterName = "CharacterEncodingFilter",urlPatterns = "/*")
public class CharacterEncodingFilter implements javax.servlet.Filter {
    //初始化
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        //Filter.super.init(filterConfig);
    }
    //Chain : 链
    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=UTF-8");

        System.out.println("CharacterEncodingFilter执行前...");
        chain.doFilter(request,response);
        System.out.println("CharacterEncodingFilter执行后...");


    }
    //销毁
    @Override
    public void destroy() {
        //Filter.super.destroy();
    }
}
